package com.itheima.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/loginController")
public class LoginController {


    @RequestMapping("/index")
    public String index()
    {
        return "index";
    }


    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String loginDisplay(Model model) throws Exception
    {
        return "login";
    }



    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String loginSubmit(HttpSession httpSession, String username, String password) throws Exception
    {
        httpSession.setAttribute("userId", 1);
        return "redirect:/loginController/index";
    }

    @RequestMapping(value = "/logout", method = RequestMethod.POST)
    public String logout(HttpSession httpSession, Integer userId)
    {
        // session过期
        httpSession.invalidate();
        return "redirect:/loginController/login";
    }

}
